﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Datos
    Private oCnn As SqlConnection
    Private Sub abrirConexion()
        'oCnn.ConnectionString = "Data Source=NOTEBOOK\SQL2005;Initial Catalog=Movimiento;Persist Security Info=True;User ID=controlf;Password=1"
        'oCnn.ConnectionString = "Data Source=030_03_13;Initial Catalog=CuentaCorriente;Integrated Security=False; User ID=controlf;Password=1"
        oCnn.ConnectionString = "Data Source=NICOLAS\SQLEXPRESS;Initial Catalog=CuentaCorriente;Integrated Security=True"
        'oCnn.ConnectionString = "Data Source=030_03_16;Initial Catalog=CuentaCorriente"                                 
        'oCnn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CuentaCorriente;Data Source=030_03_17"
        oCnn.Open()

    End Sub
    Private Sub CerrarConexion()
        oCnn.Close()
        oCnn.Dispose()
        oCnn = Nothing
    End Sub
    Public Function EjecutarSP_INT(ByVal SP As String, ByVal c As Collection) As Integer
        Dim ok As Integer = 0
        Dim oCmd As New SqlCommand
        Try
            abrirConexion()
            oCmd.Connection = oCnn
            oCmd.CommandText = SP
            oCmd.CommandType = CommandType.StoredProcedure
            SqlCommandBuilder.DeriveParameters(oCmd)
            Dim i As Integer
            For i = 1 To c.Count
                oCmd.Parameters(i).Value = c(i)
            Next
            oCmd.ExecuteNonQuery()
        Catch ex As SqlException
            ok = -1
        Catch ex As Exception
            ok = -2
        End Try
        Return ok
    End Function

    Public Function EjecutarSP_Col(ByVal SP As String) As SqlClient.SqlDataReader
        Dim dr As SqlClient.SqlDataReader
        Dim oCmd As New SqlCommand
        Try
            abrirConexion()
            oCmd.Connection = oCnn
            oCmd.CommandText = SP
            oCmd.CommandType = CommandType.StoredProcedure
            dr = oCmd.ExecuteReader
        Catch ex As SqlException
            'upsss
            MsgBox("error de SQL" & ex.Message, MsgBoxStyle.Information)
            Return Nothing
        End Try
        Return dr
    End Function

    Public Sub New()
        oCnn = New SqlConnection
    End Sub

End Class
